package com.example.framework;

import org.openqa.selenium.By;

import com.example.tests.ContactFields;

public class ContactHelper extends BaseHelper {
	
	public ContactHelper(ApplicationManager manager) {
		super(manager);
	}

	public void createContact(ContactFields contact) {
		fillInContactDetails(contact);
		click(By.name("submit"));
	}
	
	public void editContact(ContactFields contact) {
		selectContact();
		fillInContactDetails(contact);
		click(By.name("update"));
	}
	
	public void deleteContact() {
		selectContact();
		click(By.cssSelector("input[value='Delete']"));
	}
	
	public void selectContact() {
		click(By.cssSelector("table#maintable tr:nth-child(2) td:nth-child(7) a"));
	}
	
	public void fillInContactDetails(ContactFields contact) {
		type(By.name("firstname"), contact.getFirstName());
		type(By.name("lastname"), contact.getLastName());
		type(By.name("address"), contact.getAddress());
		type(By.name("home"), contact.getHome());
		type(By.name("home"), contact.getHomePhone());
		type(By.name("mobile"), contact.getMobilePhone());
		type(By.name("work"), contact.getWorkPhone());
		type(By.name("email"), contact.getEmail1());
		type(By.name("email2"), contact.getEmail2());
		selectByText(By.name("bday"), contact.getBDay());
		selectByText(By.name("bmonth"), contact.getBMonth());
		type(By.name("byear"), contact.getBYear());
		type(By.name("address2"), contact.getSecondaryAddress());
		type(By.name("phone2"), contact.getSecondaryHomePhone());
	}

}
